package com.authine.cloudpivot.ext.applicationservice.homepagedata;

import com.authine.cloudpivot.ext.applicationservice.organization.UserApi;
import com.authine.cloudpivot.ext.dto.GatewayResponse;
import com.authine.cloudpivot.ext.dto.system.UserDto;
import com.authine.cloudpivot.ext.utils.system.UserUtils;
import com.authine.hermes.app.launcher.service.ApplicationService;
import com.authine.mvp.app.launcher.domain.SelectorFormat;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.util.StopWatch;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;

import java.util.List;
import java.util.Map;

import static com.authine.hermes.app.launcher.service.ApplicationServiceFoundation.CUSTOM_SERVICE;

@Slf4j
@Path("HomePageData")
public class HomePageData extends ApplicationService {

    private final CountService countService = new CountService();

    @Path("/HomeData")
    @POST
    @Operation(summary = "首页数据", tags = CUSTOM_SERVICE)
    public GatewayResponse<String> HomeData() {

        StopWatch sw = new StopWatch();

        //获取当前用户组织ID
        UserDto currentUser = UserUtils.getCurrentUser();
        List<SelectorFormat> organization_id = currentUser.getOrganization_id();
        String orgId = organization_id.get(0).getId();

        sw.start("首页左上方数据统计");

        try {
            Map<String, Object> countMainInfo = countService.countMainInfo(orgId);
        } catch (IllegalStateException e) {
            log.error("首页左上方数据统计异常：{}，{}", ExceptionUtils.getMessage(e), ExceptionUtils.getStackTrace(e));
        }




        return null;
    }

}
